"""
Swagger 页面配置以及路由配置
"""
from django.conf import settings
from django.urls import re_path, include
from django.views.static import serve
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_view = get_schema_view(
    openapi.Info(
        title="CMDB API", # Swagger页面的标题
        default_version='v1', # 默认版本
        description="CMDB API", # 描述
        terms_of_service="https://www.google.com/policies/terms/", # 服务条款
        contact=openapi.Contact(email="contact@snippets.local"), # 联系方式
        license=openapi.License(name="BSD License"), # 许可证
    ),
    public=True, # 是否公开
    permission_classes=[permissions.AllowAny], # 权限类
)


urlpatterns = [
    re_path(r'media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}),
    re_path(r'^admin/', include('apps.vadmin.urls')),
    re_path(r'^$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
